<?php

namespace app\common\model\search;

trait FollowHistorySearch
{
    //随访日期
    public function searchFollowTimeAttr($query, $value, $data)
    {
        //$condition[] = ['pushtime', '>=', $value[0]];
        //$condition[] = ['pushtime', '<=', $value[1]];
        //return $query->where($condition);
        $condition = [];
        if (isset($value[0]) && !empty($value[0]) && $value[0] <> null && $value[0] <> '') {
            $condition[] = ['pushtime', '>=', $value[0]];
        }

        if (isset($value[1]) && !empty($value[1]) && $value[1] <> null && $value[1] <> '') {
            $condition[] = ['pushtime', '<=', $value[1]];
        }
        return $query->where($condition);
    }

    //随访人员
    public function searchStaffNameAttr($query, $value, $data)
    {
        return $query->whereLike('staffName', trim($value));
    }

    //随访方式
    public function searchModeAttr($query, $value, $data)
    {
        if (!empty($value))
        {
            return $query->where('mode', (int)$value);
        }
    }

    //随访计划
    public function searchTasknameAttr($query, $value, $data)
    {
        return $query->whereLike('taskname', trim($value));
    }

    //随访日期
    public function searchPushTimeAttr($query, $value, $data)
    {

        $condition[] = ['pushtime', '>=', $value[0]];
        $condition[] = ['pushtime', '<=', $value[1]];
        return $query->where($condition);
    }

    //患者姓名
    public function searchNameAttr($query, $value, $data)
    {
        return $query->whereLike('name', trim($value));
    }

    //随访人员id
    public function searchStaffIdAttr($query, $value, $data)
    {
        return $query->where('staffId', (int)$value);
    }

    //诊断名称
    public function searchDiagnosisAttr($query, $value, $data)
    {
        return $query->whereLike('diagnosis', trim($value));
    }
}